package com.zslc.foreignoption.controller;

import com.zslc.foreignoption.entity.TweetInfo;
import com.zslc.foreignoption.service.TweetInfoService;
import com.zslc.foreignoption.util.ResultCMS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @description:
 * @author: Gaoyc
 * @date: 2024-06-21 11:24
 **/
@Slf4j
@RequestMapping("/tweet")
@RestController
public class TweetInfoController {
    @Resource
    private TweetInfoService tweetInfoService;



    /**
     * 查询tweet账号所有帖子列表
     * @param page
     * @param pageSize
     * @return com.zslc.foreignoption.util.ResultCMS
     * @author Gaoyc
     * @date 2024/06/23 10:56
     */
    @GetMapping("/list")
    public ResultCMS list(@RequestParam(required = false) Integer page,
                                    @RequestParam(required = false) Integer pageSize){
        if (page == null || pageSize == null) {
            page = 1;
            pageSize = 10;
        }
        page = (page - 1) * pageSize;
        try {
            List<TweetInfo> list = new ArrayList<>();
            Integer count = tweetInfoService.count();
            if(count >0){
                list = tweetInfoService.list(page,pageSize);
            }
            return new ResultCMS("true", count, list);
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return ResultCMS.fail_5000();
        }
    }


}
